package middleware

import (
	api "go-gw-scaffold/api/auth"
	"net/http"

	"github.com/gin-gonic/gin"
)

func AuthorizeMiddleware() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		tokenString := ctx.GetHeader("Authorization")
		jwtToken := api.NewAuthorizeToken("tws")
		_, error := jwtToken.ParseTokenStirng(tokenString)
		if error != nil {
			ctx.JSON(http.StatusUnauthorized, gin.H{"message": "访问未授权"})
			ctx.Abort()
			return
		}
		ctx.Next()
	}
}
